<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function queryParse(url) {
            url = url.slice(url.indexOf("?") + 1).split("&")
            let obj = {}
            url.forEach((item) => {
                item = item.split("=")
                if (item[1].indexOf("#") != -1) {
                    item[1] = item[1].split("#")[0]
                }
                obj[item[0]] = item[1]
            })
            return obj
        }
        const ur = "https://www.baidu?width=251&height=360&pdi=85#name"
        const parms = queryParse(ur)
        console.log(parms)//{width:251,height:360,pdi:85}
    </script>
</body>

</html>